package com.aisile.manager.controller;

import com.aisile.commonPojo.SpectionOption;
import com.aisile.entity.PageResult;
import com.aisile.entity.Result;
import com.aisile.manager.SpecService;
import com.aisile.pojo.TbSpecification;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/spec")
public class SpecController {

    @Reference
    SpecService specService;

    @RequestMapping("/findPage")
    public PageResult findPage(int page,int rows,@RequestBody  TbSpecification tbSpecification){

        return specService.findPage(page,rows,tbSpecification);
    }
    //添加
    @RequestMapping("/save")
    public Result save(@RequestBody SpectionOption spectionOption){

        try {
           specService.insertSpection(spectionOption);
            return new Result(true,"天加成功");
        }catch(Exception e){
            return new Result(false,"添加失败");
        }
    }
    //批量删除
    @RequestMapping("/delete")
    public Result deleteAll(Long[] ids){
        try {
            specService.deleteAll(ids);
            return new Result(true,"删除成功");
        }catch(Exception e){
            return new Result(false,"删除失败");
        }
    }
   //回显
    @RequestMapping("/findOne")
    public SpectionOption findOne(Long id){
        return specService.findOne(id);
    }
    //修改
    @RequestMapping("/update")
    public Result udpate(@RequestBody SpectionOption spectionOption){
        try {
            specService.update(spectionOption);
            return new Result(true,"修改成功");
        }catch(Exception e){
            return new Result(false,"修改失败");
        }
    }
    @RequestMapping("/findSpecList")
    public List<Map> findSpecAll(){
        return specService.findSpecList();
    }
}
